package com.innovation.chengzhangriji.ui.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageView;

import com.innovation.chengzhangriji.R;

public class CuteTwoImageView extends ImageView {

    private Drawable mCuteOneSrc;

    private Drawable mCuteTwoSrc;

    public CuteTwoImageView(Context context) {
        super(context);
        init(context, null);
    }

    public CuteTwoImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public CuteTwoImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs);
    }

    public void setCuteTwoImageDrawable(Drawable cuteOneSrc, Drawable cuteTwoSrc) {
        mCuteOneSrc = cuteOneSrc;
        mCuteTwoSrc = cuteTwoSrc;
        setImageDrawable(mCuteOneSrc);
    }

    public void setInitImage() {
        setImageDrawable(mCuteOneSrc);
    }

    public void change() {
        if (mCuteOneSrc != null && mCuteTwoSrc != null) {
            if (getDrawable() == mCuteOneSrc) {
                setImageDrawable(mCuteTwoSrc);
            } else if (getDrawable() == mCuteTwoSrc) {
                setImageDrawable(mCuteOneSrc);
            }
        }
    }

    public void setChangeImage() {
        setImageDrawable(mCuteTwoSrc);
    }

    private void init(Context context, AttributeSet attrs) {
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CuteTwoImageView);
        mCuteOneSrc = typedArray.getDrawable(R.styleable.CuteTwoImageView_cute_one_src);
        mCuteTwoSrc = typedArray.getDrawable(R.styleable.CuteTwoImageView_cute_two_src);
        typedArray.recycle();
        setImageDrawable(mCuteOneSrc);
    }

}
